<?php
/**
 */
// from 0 local 1 from_mblog

define("CACHE_PREFIX_PUBU","_pubu_content");

class db_app_data_detail extends db_base {
    
	var $table_name = "app_data_detail";
	
	function db_app_data_detail()
	{
		parent::db_base();
	}
	
	

	function get_app_data_detail_item($id)
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_video."-get_app_data_detail_item-{$id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$id = intval($id);
			$where_ary = array();
			$where_ary[] = "id = $id";
			$where_ary[] = "status = 1";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,1,1,"",$where);
			
			$content[0]["content_no_url"] =  preg_replace("/http[\S]+/","",$content[0]["content"]);
			
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	
	function get_app_data_detail_item_with_del($id)
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_video."-get_app_data_detail_item_with_del-{$id}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$id = intval($id);
			$where_ary = array();
			$where_ary[] = "id = $id";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_alllist($this->table_name,1,1,"",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	function get_mblog_video_count_by_date($show_type="",$date="")
	{
		$mc = mem_cache::get_instance();
	
		$key = CACHE_PREFIX_video."-get_mblog_video_count_by_date-{$show_type}-{$date}";
		$cache = $mc->get($key);
		if ($cache === false)
		{	
			$show_type = mysql_escape_string($show_type);
			$date = mysql_escape_string($date);
			
			$where_ary = array();
			if(strlen($show_type)>0)$where_ary[] = "show_type = $show_type";
			if(strlen($date)>0)$where_ary[] = "update_date = '{$date}'";
			$where_ary[] = "status = 1";
			$where = join (" and ",$where_ary);
			
			$content = $this->get_listcount($this->table_name,$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
		
	}
	
	function admin_get_list_by_uid($p=1,$pcount=20,$uid)
	{
		$where ="create_uid = $uid and status = 1";
		$res = $this->get_alllist($this->table_name,$p,$pcount,"id desc",$where);
		
		return $res;
	}
	function admin_get_count_by_uid($uid)
	{
		$where ="create_uid = $uid and status = 1";
		$res = $this->get_listcount($this->table_name,$where);
		
		return $res;
	}
	
	
	function admin_update_by_id($id,$status="",$pic="",$link="",$content="",$pic_width="",$pic_height="")
	{
		$id = intval($id);
		$where = "id = $id";
		
		if(strlen($status)>0)$ary["status"] = $status;
		if(strlen($pic)>0)$ary["pic"] = $pic;
		if(strlen($link)>0)$ary["link"] = $link;
		if(strlen($content)>0)$ary["content"] = $content;
		if(strlen($pic_width)>0)$ary["pic_width"] = $pic_width;
		if(strlen($pic_height)>0)$ary["pic_height"] = $pic_height;
		
		
		$res = $this->update($this->table_name,$ary,$where);
		
		return $res;
	}
	
	
	function admin_insert_one($pic="",$link="",$content="",$uid="",$pic_width="",$pic_height="",$user_nickname="")
	{
		$id = intval($id);
		$where = "id = $id";
		
		$ary["status"] = 1;
		$ary["pic"] = $pic;
		$ary["link"] = $link;
		$ary["content"] = $content;
		
		
		$ary["pic_width"] = $pic_width;
		$ary["pic_height"] = $pic_height;
		
		$ary["create_nickname"] = $user_nickname;
		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["create_uid"] = $uid;
		
		$res = $this->insert($this->table_name,$ary);
		
		if($res)
		{
			return $this->get_lastinsertid();
		}
		else
		{
			return false;
		}
		
	}
	
	
	
	
}



